import { Button, message } from "@/components/base";
import React from "react";
import * as apis from "@/apis";

/** 发起审批 */
export function InitiateApproval(props: {
    record: any,
    index: number
    refresh: () => Promise<void>,
}) {
    const { record, refresh } = props;
    const onClick = React.useCallback(async () => {
        await apis.order.update.post({ id: record.id, orderStatus: apis.order.OrderStatus.待审核 });
        refresh();
        message.success('发起审批成功');
    }, [record.id, refresh]);

    if (record.orderStatus !== apis.order.OrderStatus.待下单) return <></>
    return (
        <Button type='link' onClick={onClick} >发起审批</Button>
    )
}
